#ifndef __CRANDOM_H__
#define __CRANDOM_H__

// Additive congruential
// a[0] = seed
// a[i] = (b*a[i]) % m , i < c
// a[j] = (a[j-b] + a[j-c]) % m, j >= c
#define RND_MAX_VAL_SHIFT	30
#define RND_MAX_VAL_MASK	0x3fffffffl
#define RND_HALF_MAX_VAL_SHIFT	15
#define RND_HALF_MAX_VAL_MASK	0x7fffl
#define RND_C				55
#define RND_B				31

class CRandom
{
public:
	CRandom();
	CRandom(unsigned long seed);
	void SetSeed(unsigned long seed);
	unsigned int NextInt(unsigned int max);
	unsigned int NextTrueFalse();
	unsigned int NextTrue(unsigned int percent);
private:
	unsigned long m_Val[RND_C];
	unsigned int m_iRandomIndex;
private:
	unsigned long Mult(unsigned long a, unsigned long b);
};

#endif